
import http from 'http';
import chalk from 'chalk';

const server = http.createServer((req, res) => {
  const requestLine = `${req.method} ${req.url} HTTP/${req.httpVersion}`;
  console.log(chalk.greenBright(requestLine));

  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello World');
});

server.listen(8080, () => {
  console.log('Server running at http://localhost:8080/');
});

//复制 04-export-object.mjs 为 09-export-object.mjs，并修改代码，用 ES6 的 export 关键字导出 Circle 类
class Circle {
    constructor(radius) {
      this.radius = radius;
    }
  
    getCircumference() {
      return 2 * Math.PI * this.radius;
    }
  
    getArea() {
      return Math.PI * this.radius * this.radius;
    }
  }
  
  export default Circle;

  //import 导入 09-export-object.js 的 Circle 类，并根据命令行参数的 radius 数据，控制台输出圆的周长和面积信息：
  import Circle from './09-export-object.mjs';

const radius = process.argv[2];
if (!radius) {
  console.error('Please provide a radius value');
  process.exit(1);
}

const circle = new Circle(parseFloat(radius));
console.log(`Circumference: ${circle.getCircumference()}`);
console.log(`Area: ${circle.getArea()}`);